#!/bin/sh
sdd_name=''
# get dev name, from $MDEV
sdd_name=$1
dev_path=$2
dev_type=$3
action=$4
# did we detect a valid USB mass storage device
if [ "$sdd_name" = "" ]; then
   echo "$MDEV=NULL" >> /var/volatile/hotplug.log
   exit
fi
# mount point
MNT_DIR="/mnt/usb/$sdd_name"
#debug
echo "sdd:$action  / mdev: $MDEV / devpath: $dev_path / subsystem: $SUBSYSTEM / mntdir: $MNT_DIR" >> /var/volatile/hotplug.log
# check mount / unmount
if [ $action = "remove" ]; then
   # debug
   #echo `lsof -t "$MNT_DIR"` >> /var/volatile/hotplug.log
   echo `lsof | grep "$MNT_DIR"` >> /var/volatile/hotplug.log
   # send notification to process with mounted files open
   #kill -HUP `lsof | grep "$MNT_DIR"`
   kill -INT `lsof | grep "$MNT_DIR"`
   # unmount
   /bin/umount -lf /dev/$1
   /bin/rm -rf "$MNT_DIR"
else
   # mount
   if [ ! -d "$MNT_DIR" ]; then
      /bin/mkdir -p "$MNT_DIR"
   fi
#   /bin/mount -t vfat -o codepage=936,iocharset=utf8 /dev/$1 "$MNT_DIR"
   /bin/mount -t vfat /dev/$1 "$MNT_DIR"
fi
